// pages/my/index.js
const app = getApp()

Page({
  data: {
    topBarStatusHeight: 0
  },

  onLoad() {
    const topBarStatusHeight = wx.getSystemInfoSync()
    // console.log(topBarStatusHeight.statusBarHeight)
    this.setData({
      topBarStatusHeight: topBarStatusHeight.statusBarHeight
    })

    const token = app.token
    this.setData({
      token
    })

    if (app.token) this.getUserInfo()
  },

  async getUserInfo() {
    const {data, statusCode} = await wx.http.get('/user/info')
    const {nick_name, mobile, balance, avatar, points} = data.data.userInfo
    if (statusCode !== 200) return wx.utils.toast()
    this.setData({
      nick_name,
      mobile,
      balance,
      avatar,
      points: String(points)
    })
  }
})